// pages/validate/validate.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    "name":"",
      "nickname":"",
      "password":"",
      "select_gender":false,
      "gender":"--请选择--",
      "genders": ['男', '女'],
      "sno":"",
      "select_academy":false,
      "academies":['计算机学院','医学院','电子信息学院','文学院','法学院','经济与管理学院','数学与统计学院'],
      "academy":'--请选择--',
      "select_dorm":false,
      "dorms":['国软C3','国软C4','国软C7'],
      "dorm":'--请选择--',
      "mobile":"",
      "email":"",
    "validatecode":"",
    "wrongtext":"",
    "wrong":false,
    "code":""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options.password)
    let that=this
    this.setData({
      ['user.nickname']:options.nickname,
      ['user.password']:options.password
    })
  },
  bindShowMsg_gender() {
    this.setData({
      select_gender: true,
      select_academy:false,
      select_dorm:false
    })
  },
  mySelect_gender(e) {
    console.log(e)
    var name = e.currentTarget.dataset.name
    this.setData({
      gender: name,
      select_gender: false
    })
  },
  bindShowMsg_academy() {
    this.setData({
      select_academy: true,
      select_dorm:false,
      select_gender:false
    })
  },
  mySelect_academy(e) {
    console.log(e)
    var name = e.currentTarget.dataset.name
    this.setData({
      academy: name,
      select_academy: false
    })
  },
  bindShowMsg_dorm() {
    this.setData({
      select_dorm: true,
      select_gender:false,
      select_academy:false
    })
  },
  mySelect_dorm(e) {
    console.log(e)
    var name = e.currentTarget.dataset.name
    this.setData({
      dorm: name,
      select_dorm: false
    })
  },
  sendCode(){
    let that=this
    if(this.data.email!=''&&this.data.email!=null){
      wx.request({
        url: 'http://localhost:8080/user/code',
        method:'POST',
        data:({
          "email":that.data.email
        })
      })
    }else{
      this.setData({
        wrong:true,
        wrongtext:"请输入正确邮箱"
      })
    }
  },
  submit(){ 
    let that=this
    wx.request({
      url: 'http://localhost:8080/user/register',
      method:'post',
      data:({
        "name":that.data.name,
        "nickname":that.data.nickname,
        "password":that.data.password,
        "school":that.data.academy,
        "gender":that.data.gender,
        "sno":that.data.sno,
        "phone":that.data.mobile,
        "email":that.data.email,
        "code":that.data.code
      })
    })
  }
})